package org.lemon.transport.context.data.message;

import com.google.protobuf.ByteString;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;

import java.io.Serializable;
import java.util.UUID;

@Data
@Slf4j
public class ToRuleEngineMessage implements Serializable {

    private final String queueName;
    private final UUID id;
    private final long ts;
    private final String type;
    private final String originator;
    private final Long projectId;
    private final MessageMetaData metaData;
    private final MessageDataType dataType;
    private final String data;
    private final Long ruleChainId;
    private final Long ruleNodeId;


    public ToRuleEngineMessage(String queueName, UUID id, long ts, String type, String originator, Long projectId, MessageMetaData metaData, MessageDataType dataType, String data, Long ruleChainId, Long ruleNodeId) {
        this.queueName = queueName;
        this.id = id;
        this.ts = ts;
        this.type = type;
        this.originator = originator;
        this.projectId = projectId;
        this.metaData = metaData;
        this.dataType = dataType;
        this.data = data;
        this.ruleChainId = ruleChainId;
        this.ruleNodeId = ruleNodeId;
    }

    public static ToRuleEngineMessage newMessage(String queueName, String type, String originator, Long projectId, MessageMetaData metaData, String data, Long ruleChainId, Long ruleNodeId) {
        return new ToRuleEngineMessage(queueName, UUID.randomUUID(), System.currentTimeMillis(), type, originator, projectId,
                metaData.copy(), MessageDataType.JSON, data, ruleChainId, ruleNodeId);
    }

    public static ByteString toByteString(ToRuleEngineMessage msg) {
        return ByteString.copyFrom(toByteArray(msg));
    }

    public static byte[] toByteArray(ToRuleEngineMessage msg) {
        return null;
    }
}
